const store = require("./store");
const { addAction, minusAction } = require("./actionCreators");

console.log("init: ", store.getState());

// 订阅store的变化
const unsubscribe = store.subscribe(() => {
  console.log("update: ", store.getState());
});

setTimeout(() => {
  // 取消订阅
  unsubscribe();
}, 3000);

// 派发action, 这样写了很多重复
// store.dispatch({ type: "ADD", payload: 10 });
// store.dispatch({ type: "MINUS", payload: 1 });
// store.dispatch({ type: "MINUS", payload: 1 });
// store.dispatch({ type: "MINUS", payload: 1 });
// store.dispatch({ type: "MINUS", payload: 1 });

// 派发函数是其他地方到处要用的，一般不会写在这里
// addAction, minusAction也是用到的时候传进来的，属于业务代码
store.dispatch(addAction(10));
store.dispatch(minusAction(1));
store.dispatch(minusAction(1));
store.dispatch(minusAction(1));
